home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: division problem
- Date: 26 Jan 1996 22:08 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <26JAN199622082450@erich.triumf.ca>
- References: <31097D77.11AA@rain.org>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <31097D77.11AA@rain.org>, tpaul <tpaul@rain.org> writes...
- >Can anyone show me why this does not work? I am a beginner.
- >
- >#include <stdio.h>
- >
- >main ()
- >{
- > int fahrenheit, celsius;
- >
- > printf("Fahrenheit temperature =?";
- > scanf("%d",fahrenheit);
- > celsius = 5/9*(fahrenheit-32);
-
- This calculation will be done with ints, and 5/9 in integer arithmetic is 0.
-
- Also (if I have the precedence rules right), it will be done as:
- 5
- ----------------------
- 9 * (fahrenheit - 32)
-
- In order to make it work, you could do:
- celsius = (int)((5.0/9.0) * (fahrenheit - 32))
- The 5.0/9.0 give a meaningful result, and force the multiplication to be done
- with floats. The (int) will convert the result back to an int.
-
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-